<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->

        <el-input v-model="query.xm" clearable size="small" placeholder="姓名" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.sfz" clearable size="small" placeholder="身份证" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.bisZhsqCblx" clearable size="small" placeholder="参保类型" class="filter-item" style="width: 120px" @change="crud.toQuery">
          <el-option
            v-for="item in cblxTypeOptions"
            :key="item.key"
            :label="item.display_name"
            :value="item.key"
          />
        </el-select>
        <el-select v-model="query.sndj" clearable size="small" placeholder="失能登记" class="filter-item" style="width: 120px" @change="crud.toQuery">
          <el-option
            v-for="item in sndjTypeOptions"
            :key="item.key"
            :label="item.display_name"
            :value="item.key"
          />
        </el-select>
        <el-select v-model="query.tcq" clearable size="small" placeholder="医保所属区县" class="filter-item" style="width: 130px" @change="crud.toQuery">
          <el-option
            v-for="item in dict.ccstcqh"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="660px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="姓名" prop="bisZhsqSnryXm">
            <el-input v-model="form.bisZhsqSnryXm" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="身份证" prop="bisZhsqSnrySfz">
            <el-input v-model="form.bisZhsqSnrySfz" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="性别" prop="bisZhsqSnryXb">
            <el-input v-model="form.bisZhsqSnryXb" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="年龄" prop="bisZhsqNl">
            <el-input v-model="form.bisZhsqNl" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="医保卡号" prop="bisZhsqYbkh">
            <el-input v-model="form.bisZhsqYbkh" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="参保状态" prop="bisZhsqCbzt">
            <el-input v-model="form.bisZhsqCbzt" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="参保类型" prop="bisZhsqCblx">
            <el-input v-model="form.bisZhsqCblx" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="医保所属区县" prop="bisZhsqSnryYbssqx">
            <el-select v-model="form.bisZhsqSnryYbssqx" filterable placeholder="请选择" disabled style="width: 170px;">
              <el-option
                v-for="item in dict.ccstcqh"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="联系电话" prop="bisZhsqLxdh">
            <el-input v-model="form.bisZhsqLxdh" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="地址" prop="bisZhsqHldz">
            <el-input v-model="form.bisZhsqHldz" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="监护人姓名" prop="bisZhsqJhrxm">
            <el-input v-model="form.bisZhsqJhrxm" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="监护人电话" prop="bisZhsqJhrdh">
            <el-input v-model="form.bisZhsqJhrdh" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="关系" prop="bisZhsqGx">
            <el-select v-model="form.bisZhsqGx" filterable placeholder="请选择" style="width: 170px;">
              <el-option
                v-for="item in dict.yjsgx"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="!this.sbIsExist" label="ADL量表评分" prop="bisZhsqAdl">
            <el-input v-model="form.bisZhsqAdl" readonly style="width: 170px;" />
          </el-form-item>
          <el-form-item label="申请原因" prop="bisZhsqSqyy">
            <el-input v-model="form.bisZhsqSqyy" :rows="3" type="textarea" style="width: 470px;" />
          </el-form-item>
          <el-upload
            v-if="!this.sbIsExist"
            ref="upload_adl"
            disabled="true"
            :auto-upload="true"
            :on-preview="handlePreview"
            :before-upload="beforeVideoUpload"
            :before-remove="beforeRemove"
            :on-remove="handleRemove"
            :on-success="handleVideoSuccess"
            :on-error="handleError"
            :data="fjlb_adl"
            :headers="headers"
            :file-list="file_list_adl"
            :action="minioMpUploadVideoApi"
          />
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="crud.cancelCU">关 闭</el-button>
          <el-button type="info" @click="zhHistoryQuery()">查看意见</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column align="center" prop="bisZhsqZt" label="申请状态" width="130">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bisZhsqZt === '05'" effect="plain" type="">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
            <el-tag v-else-if="scope.row.bisZhsqZt === '00'" effect="plain" type="warning">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
            <el-tag v-else effect="plain" type="danger">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="lrsj" label="申请时间" width="150" />
        <el-table-column align="center" prop="bisZhsqYbkh" label="医保卡号" width="90" />
        <el-table-column align="center" prop="bisZhsqSnryXm" label="姓名" />
        <el-table-column align="center" prop="bisZhsqSnryXb" label="性别" />
        <el-table-column align="center" prop="bisZhsqSnrySfz" label="身份证" width="150" />
        <el-table-column align="center" prop="bisZhsqNl" label="年龄" />
        <el-table-column prop="bisZhsqDykkrq" label="待遇开始日期" width="100" />
        <el-table-column prop="bisZhsqDyjsrq" label="待遇结束日期" width="100" />
        <el-table-column align="center" prop="bisZhsqSndj" label="失能等级" />
        <el-table-column align="center" prop="bisZhsqAdl" label="ADL评分" />
        <el-table-column align="center" prop="bisZhsqLxdh" label="联系电话" width="100" />
        <el-table-column align="center" prop="bisZhsqJhrxm" label="监护人姓名" />
        <el-table-column align="center" prop="bisZhsqJhrdh" label="监护人电话" width="130" />
        <el-table-column align="center" prop="bisZhsqGxName" label="关系" />
        <el-table-column align="center" prop="bisZhsqSnryYbssqxName" label="医保所属区县" width="130" />
        <el-table-column fixed="right" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click.native.prevent="recall(scope.$index, scope.row)"
            >
              查 看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <el-dialog :visible.sync="dialogYjFormVisible" width="720px">
        <el-table ref="yjtable" v-loading="this.zhHistoryDataloading" :data="zhHistoryData">
          <el-table-column type="index" :index="indexMethod" label="序号" align="center" />
          <el-table-column prop="lrsj" label="操作时间" align="center" />
          <el-table-column prop="lrrxm" label="操作人" align="center" />
          <el-table-column prop="type" label="操作类型" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.type === '02'" effect="plain" type="success">
                评估
              </el-tag>
              <el-tag v-else-if="scope.row.type === '04'" effect="plain" type="primary">
                复核
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="result" label="操作结果" align="center" />
          <el-table-column prop="bz" label="意见" align="center" width="200px" />
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogYjFormVisible = false">关 闭</el-button>
        </div>
      </el-dialog>
      <image-viewer
        v-if="showImgViewer"
        :url-list="imgPreviewUrl"
        :on-close="() => {showImgViewer = false}"
        :z-index="3000"
      />
    </div>
  </div>
</template>

<script>
import crudZhsq from '@/api/business/zhsq'
import crudFile from '@/api/tools/localStorage'
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import { getYbry } from '@/api/business/ybry'
import { getAdlXmxx } from '@/api/business/adlXmxx'
import { queryThisHljg } from '@/api/business/hljg'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'
import moment from 'moment'
import ImageViewer from 'element-ui/packages/image/src/image-viewer'
import axios from 'axios'

const defaultForm = { bisZhsqId: null, bisZhsqHljgId: null, bisZhsqSnryId: null, bisZhsqSnryXm: null, bisZhsqSnryXb: null, bisZhsqSnrySfz: null, bisZhsqDykkrq: null, bisZhsqYbkh: null, bisZhsqCbzt: null, bisZhsqDyjsrq: null, bisZhsqXsdyq: null, bisZhsqAdl: null, bisZhsqZt: null, bisZhsqSnryYbssqx: null, ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, bz: null, bisZhsqAdlPc: null, bisZhsqSndj: null, bisZhsqRybh: null, bisZhsqNl: null, bisZhsqLxdh: null, bisZhsqHldzSsqx: null, bisZhsqHldzXxdz: null, bisZhsqHldz: null, bisZhsqJhrxm: null, bisZhsqJhrdh: null, bisZhsqGx: null, bisZhsqSqyy: null, bisZhsqGrbh: null, adlZhsqs: [], bisZhsqCblx: null }
export default {
  name: 'ZhsqJgBh',
  components: { pagination, rrOperation, ImageViewer },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['xb', 'yjsgx', 'ccs', 'zhzt', 'ccstcqh'],
  cruds() {
    return CRUD({ title: '照护申请', url: 'api/zhsqQuery/querOrgYbhZhsqxx', idField: 'bisZhsqId', sort: 'bisZhsqId,desc', crudMethod: { ...crudZhsq }})
  },
  data() {
    return {
      dialogYjFormVisible: false,
      snryDrawer: false,
      ybrySfzh: '',
      adlDrawer: false,
      /* ALD选题按钮是否可用 */
      adlIsDisabled: false,
      snryData: [],
      zhHistoryData: [],
      adlData: [],
      headers: { 'Authorization': getToken() },
      /* 上传附件时，附件类别（病历） */
      fjlb_bl: { 'fjlb': 'BL' },
      /* 上传附件时，附件类别（社会保障卡） */
      fjlb_shbzk: { 'fjlb': 'SHBZK' },
      /* 上传附件时，附件类别（身份证） */
      fjlb_sfz: { 'fjlb': 'SFZ' },
      /* 上传附件时，附件类别（ADL量表） */
      fjlb_adl: { 'fjlb': 'orgAdlLiveVideo' },
      /* 默认加载上传的文件列表 */
      file_list_bl: [],
      file_list_shbzk: [],
      file_list_sfz: [],
      file_list_adl: [],
      fileIds: '',
      fileVideoIds: '',
      fileAllIds: '',
      showImgViewer: false,
      imgPreviewUrl: [], // 当前要放大的图片存放位置
      sbIsExist: true,
      pgIsExist: true,
      sstcq: '',
      snryDataloading: false,
      zhHistoryDataloading: false,
      fullscreenLoading: false,
      radio4: 'ReadCardBas',
      cblxTypeOptions: [
        { key: '城乡居民', display_name: '城乡居民' },
        { key: '城镇职工', display_name: '城镇职工' }
      ],
      sndjTypeOptions: [
        { key: '中度失能', display_name: '中度失能' },
        { key: '重度失能', display_name: '重度失能' },
        { key: '85周岁以上', display_name: '85周岁以上' },
        { key: '90周岁以上', display_name: '90周岁以上' }
      ],
      permission: {
        add: ['admin', 'zhsq:add'],
        edit: ['admin', 'zhsq:edit'],
        del: ['admin', 'zhsq:del']
      },
      rules: {
        bisZhsqSnryXm: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        bisZhsqSnryXb: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        bisZhsqSnrySfz: [
          { required: true, message: '身份证不能为空', trigger: 'blur' }
        ],
        bisZhsqHldz: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        bisZhsqJhrxm: [
          { required: true, message: '监护人姓名不能为空', trigger: 'blur' }
        ],
        bisZhsqJhrdh: [
          { required: true, message: '监护人电话不能为空', trigger: 'blur' }
        ],
        bisZhsqGx: [
          { required: true, message: '与失能人员关系不能为空', trigger: 'blur' }
        ],
        bisZhsqSqyy: [
          { required: true, message: '申请原因不能为空', trigger: 'blur' }
        ],
        bisZhsqAdl: [
          { required: true, message: '选择ADL量表', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'baseApi',
      'fileUploadApi',
      'minioUploadImageApi',
      'minioMpUploadImageApi',
      'minioUploadVideoApi',
      'minioMpUploadVideoApi',
      'imagesUploadApi'
    ])
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    /**
     * 点击新建/编辑之前
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeToCU]() {
      this.queryThisHljg()
      return true
    },
    /**
     * 点击新建之前
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeToAdd]() {
      this.adlIsDisabled = false
      this.file_list_bl = []
      this.file_list_shbzk = []
      this.file_list_sfz = []
      this.file_list_adl = []
      this.fileAllIds = ''
      this.fileIds = ''
      this.fileVideoIds = ''
      return true
    },
    /**
     * 点击修改之前
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeToEdit](crud, form) {
      console.log(form)
      this.file_list_bl = []
      this.file_list_shbzk = []
      this.file_list_sfz = []
      this.file_list_adl = []
      this.fileAllIds = ''
      this.fileIds = ''
      this.fileVideoIds = ''
      // 清空附件列表
      this.getFiles()
      return true
    },
    /**
     * 点击删除之前校验
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeDelete](crud, form) {

    },
    /**
     * 序号
     * @param index
     * @returns {*}
     */
    indexMethod(index) {
      return index + 1
    },
    /**
     * 撤回
     * @param index
     * @param rows
     */
    recall(index, rows) {
      this.crud.toEdit(rows)
    },
    /**
     * 确认选择的失能人员
     * @param index
     * @param rows
     */
    selectRow(index, rows) {
      const snry = rows[index]
      console.log(snry)

      if (!(snry.aab034Code === this.sstcq || snry.aab034Code === '220101')) {
        this.$message({
          showClose: true,
          message: '此人医保所属统筹区为【' + snry.aab034Name + '】，本院为【' + this.dict.label.ccstcqh[this.sstcq] + '】，不符合申请条件',
          type: 'warning'
        })
        return
      }

      // 校验参保状态
      if (snry.aac031 === '停保') {
        this.$message({
          showClose: true,
          message: '此人【已停保】，无法申请照护待遇',
          type: 'warning'
        })
        return
      }
      // 校验是否缴费
      if (snry.clctClag === '') {
        this.$message({
          showClose: true,
          message: '此人【未缴费】，无法申请照护待遇',
          type: 'warning'
        })
        return
      }
      // 校验人员类型
      if (snry.akc021 === '离休或一级保健对象') {
        this.$message({
          showClose: true,
          message: '人员类型为【离休或一级保健对象】，无法申请照护待遇',
          type: 'warning'
        })
        return
      }
      // 校验是否住院
      // 校验是否正在享受待遇
      if (snry.akb021 !== '') {
        this.$message({
          showClose: true,
          message: '此人正在【' + snry.akb021 + '】享受照护待遇，无法申请',
          type: 'warning'
        })
        return
      }
      this.snryDrawer = false

      // const csrq = snry.aac002.substring(6, 13)
      const csnd = snry.aac002.substring(6, 10)
      const csrq = snry.aac002.substring(10, 14)
      // const csnd = 1937
      // const csrq = 1208
      const currentNd = moment(new Date()).format('YYYY')
      const currentRq = moment(new Date()).format('MMDD')
      // 当前日期 >= 出生日期的，年龄+1
      const nl = currentRq >= csrq ? currentNd - csnd : currentNd - csnd - 1

      this.form.bisZhsqGrbh = snry.aac001
      this.form.bisZhsqSnryXm = snry.aac003
      this.form.bisZhsqSnryXb = snry.xb
      this.form.bisZhsqSnrySfz = snry.aac002
      this.form.bisZhsqYbkh = snry.cardno
      this.form.bisZhsqCbzt = snry.aac031
      this.form.bisZhsqCblx = snry.aac008
      this.form.bisZhsqNl = nl
      // this.form.bisZhsqNl = 85
      this.form.bisZhsqSnryYbssqx = snry.aab034Code
      console.log('nl {} ', this.form.bisZhsqNl)
      this.form.bisZhsqAdl = this.form.bisZhsqNl >= 85 ? 100 : this.form.bisZhsqAdl
    },
    /**
     * 打开失能人员时，实时查询
     */
    getSnry() {
      this.snryDrawer = true
      this.ybrySfzh = ''
      this.snryData = []
    },
    /**
     * 查询医保人员
     */
    ybryQuery() {
      if (this.ybrySfzh === '') {
        this.$message({
          showClose: true,
          message: '请输入查询条件',
          type: 'warning'
        })
        return
      }

      if (this.ybrySfzh.length !== 18) {
        this.$message({
          showClose: true,
          message: '身份证不正确',
          type: 'warning'
        })
        return
      }

      this.snryDataloading = true
      getYbry({ sfzh: this.ybrySfzh }).then(res => {
        this.snryData = res.content
        this.snryDataloading = false
      }).catch(err => {
        this.snryDataloading = false
        console.log(err.data.message)
      })
    },
    /**
     * 查询医保人员
     */
    zhHistoryQuery() {
      this.dialogYjFormVisible = true
      console.log(this.zhHistoryData.length === 0)
      this.zhHistoryDataloading = true
      crudZhsq.getZhHistory({ zhsqId: this.form.bisZhsqId, sort: 'lrsj,desc' }).then(res => {
        console.log(res)
        this.zhHistoryData = res.content
        this.zhHistoryDataloading = false
      }).catch(err => {
        this.zhHistoryDataloading = false
        console.log(err.data.message)
      })
    },
    /**
     * 打开ADL量表时，实时查询
     */
    getAdl() {
      if (this.adlIsDisabled) {
        this.$message({
          dangerouslyUseHTMLString: true,
          showClose: true,
          message: 'ADL量表已完成，修改时无法操作',
          type: 'warning'
        })
      } else {
        this.adlDrawer = true
        if (this.crud.status.add === 1 && this.crud.status.edit === 0) { // 点击新增按钮，提交的时候只是新增
          getAdlXmxx().then(res => {
            console.log(res)
            this.adlData = res.adlData
            this.form.bisZhsqAdlPc = res.adlPcId
          })
        } else if (this.crud.status.add === 0 && this.crud.status.edit === 1) { // 修改照护申请时，不允许修改ADL量表
          getAdlXmxx().then(res => {
            console.log(res)
            this.adlData = res.adlData
            this.form.bisZhsqAdlPc = res.adlPcId
          })
        }
      }
    },
    /**
     * 修改操作时，需要加载附件信息
     */
    getFiles() {
      crudFile.queryFileByFjlb2(this.form.bisZhsqId).then(res => {
        for (let i = 0; i < res.length; i++) {
          const file = res[i]
          if (file.fjlb === 'orgAdlLiveVideo') {
            const obj = { 'id': file.id, 'name': file.name, 'url': file.path2 }
            this.file_list_adl.push(obj)
            this.fileVideoIds += file.id + ','
          }
        }
      })
    },
    /**
     * 记录ADL量表，并计算ADL量表总分数
     */
    adlSubmit() {
      // 是否被选中
      let selected = false
      // 未被选中的项目
      let allUnSelectedName = ''
      // ADL量表总分数
      let adlfx = 0
      // 清空选中的adl量表内容
      this.form.adlZhsqs = []
      this.adlData.map((item, index) => {
        // 项目ID
        const adlXmId = item.adlXmId
        // 项目分组
        const adlXmGroup = item.adlXmGroup
        // 项目名称
        const adlXmName = item.adlXmName
        // 项目名称
        const adlXmPx = item.adlXmPx
        // 项目选项列表
        const adlXmList = item.adlXmList

        if (adlXmId === adlXmGroup) {
          selected = selected || true
          allUnSelectedName += adlXmPx + '、' + adlXmName + '<br>'
        } else {
          for (const adlxmxx of adlXmList) {
            // 项目选项ID
            const adlXmxxId = adlxmxx.adlXmxxId
            // 项目选项分数
            const adlXmxxFs = parseInt(adlxmxx.adlXmxxFs)
            if (adlXmGroup === adlXmxxId) {
              this.form.adlZhsqs.push(adlxmxx)
              adlfx += adlXmxxFs
            }
          }
        }
        // eslint-disable-next-line no-empty
      })
      console.log('总分：' + JSON.stringify(this.form))
      if (selected) {
        this.$message({
          dangerouslyUseHTMLString: true,
          showClose: true,
          message: allUnSelectedName + '<br>没有被选中',
          type: 'warning'
        })
      } else {
        this.adlDrawer = false
        this.form.bisZhsqAdl = adlfx
      }
    },
    /**
     * 自定义保存
     * @param zt
     */
    doSave(zt) {
      this.fileAllIds = this.fileVideoIds
      this.form.bisZhsqZt = zt
      const titleMsg = '保存成功'
      this.crud.findVM('form').$refs['form'].validate(valid => {
        if (!valid) {
          return
        }

        if (this.crud.status.add === 1 && this.crud.status.edit === 0) { // 点击新增按钮，提交的时候只是新增
          this.crud.status.add = CRUD.STATUS.PROCESSING
          crudZhsq.add(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.add = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.add = CRUD.STATUS.PREPARED
              console.log(err)
            })
        } else if (this.crud.status.add === 0 && this.crud.status.edit === 1) { // 点击修改按钮，提交的时候只是修改
          this.crud.status.edit = CRUD.STATUS.PROCESSING
          crudZhsq.edit(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.edit = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.edit = CRUD.STATUS.PREPARED
              console.log(err)
            })
        }
      })
    },
    /**
     * 自定义保存
     * @param zt
     */
    doSubmit(zt) {
      if (!this.sbIsExist) {
        if (this.form.bisZhsqNl < 85) {
          if (this.fileVideoIds === '') {
            this.$notify({
              title: '提交时，需要上传视频',
              type: 'error',
              duration: 2500
            })
            return
          }
        }
      }
      this.fileAllIds = this.fileVideoIds
      this.form.bisZhsqZt = zt
      const titleMsg = '提交成功'
      this.crud.findVM('form').$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        if (this.crud.status.add === 1 && this.crud.status.edit === 0) { // 点击新增按钮，提交的时候只是新增
          this.crud.status.add = CRUD.STATUS.PROCESSING
          crudZhsq.submitZhsq(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.add = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.add = CRUD.STATUS.PREPARED
              console.log(err)
            })
        } else if (this.crud.status.add === 0 && this.crud.status.edit === 1) { // 点击修改按钮，提交的时候只是修改
          this.crud.status.edit = CRUD.STATUS.PROCESSING
          crudZhsq.submitZhsq(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.edit = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.edit = CRUD.STATUS.PREPARED
              console.log(err)
            })
        }
      })
    },
    /**
     * ADL量表关闭
     */
    handleClose() {
      this.$confirm('关闭以后，选择的内容将会消失，确认关闭？')
        .then(_ => {
          this.adlDrawer = false
        })
        .catch(_ => {})
    },
    /**
     * 上传前校验
     * @param file
     * @returns {boolean}
     */
    beforeUpload(file) {
      let isLt2M = true
      isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.loading = false
        this.$message.error('上传文件大小不能超过 10MB!' + (file.size / 1024 / 1024))
      }
      return isLt2M
    },
    /**
     * 视频上传前校验
     * @param file
     * @returns {boolean}
     */
    beforeVideoUpload(file) {
      let isLt2M = true
      isLt2M = file.size / 1024 / 1024 < 150
      if (!isLt2M) {
        this.loading = false
        // this.$message.error('上传文件大小不能超过 200MB!' + (file.size / 1024 / 1024))
        this.$notify({
          title: '上传文件大小不能超过 150MB!',
          type: 'error',
          duration: 5000
        })
      }
      return isLt2M
    },
    /**
     * 删除前确认提示
     * @param file
     * @returns {Promise<MessageBoxData>}
     */
    beforeRemove(file) {
      console.log('删除前确认提示 :{}', file)
      return this.$confirm(`删除操作会直接删除此图片，确定删除 ${file.name}？`)
    },
    /**
     * 图片预览
     * @param file
     */
    handlePreview(file) {
      console.log('图片预览 :{}', file)
      if (file.response) {
        this.imgPreviewUrl[0] = file.response.data.url2
        window.open(file.response.data.url2)
      } else {
        this.imgPreviewUrl[0] = file.url
        window.open(file.url)
      }
    },
    /**
     * 文件上传成功时的钩子
     * @param response
     * @param file
     * @param fileList
     */
    handleSuccess(response, file, fileList) {
      console.log('文件上传成功时的钩子response :{}, file{}', response, file)
      this.fileIds += response.data.id + ','
      this.crud.notify('上传成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
    },
    /**
     * 视频上传成功时的钩子
     * @param response
     * @param file
     * @param fileList
     */
    handleVideoSuccess(response, file, fileList) {
      console.log('文件上传成功时的钩子response :{}, file{}', response, file)
      this.fileVideoIds += response.data.id + ','

      // crudFile.updateYwid2ById(response.data.adlXmGroup, file.data.id).then(res => {})
      this.crud.notify('上传成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
    },
    /**
     * 移除文件
     * @param file
     * @param fileList
     */
    handleRemove(file, fileList) {
      console.log('移除文件 :{}', file, fileList)
      crudFile.del([file.id]).then(res => {})
    },
    /**
     * 监听上传失败
     * @param e
     * @param file
     * @param fileList
     */
    handleError(e, file, fileList) {
      const msg = JSON.parse(e.message)
      this.$notify({
        title: msg.message,
        type: 'error',
        duration: 2500
      })
      this.loading = false
    },
    /**
     * 查询本机构，是否绑定对应的商保/评估公司
     * false：未绑定；true：绑定
     */
    queryThisHljg() {
      queryThisHljg().then(res => {
        this.sbIsExist = res.sbIsExist
        this.pgIsExist = res.pgIsExist
        this.sstcq = res.sstcq
      })
    },
    // 获取弹窗内评估公司数据
    read() {
      this.fullscreenLoading = true
      axios.get('http://127.0.0.1:19995?MSG=' + this.radio4).then(res => {
        this.fullscreenLoading = false
        if (this.radio4 === 'ReadCardBas') {
          const shbzkContent = res.data.pCardInfo
          if (shbzkContent === '') {
            this.$notify({
              title: '重新读卡',
              type: 'warning',
              duration: 2500
            })
            return
          } else {
            const contentList = shbzkContent.split('|')
            this.ybrySfzh = contentList[1]
          }
        } else {
          const pOutBuff = res.data.pOutBuff
          if (pOutBuff === '证件信息失败') {
            this.$notify({
              title: '请将身份证放入正确位置',
              type: 'error',
              duration: 2500
            })
          } else {
            this.ybrySfzh = pOutBuff.split('|')[0]
          }
        }
        this.ybryQuery()
      }).catch(err => {
        this.fullscreenLoading = false
        console.log('err: {} ', err)
      })
    }
  }
}
</script>

<style scoped>

</style>
